使用位运算对两个数求和 您所在的位置:网站首页 1-100求和 python 使用位运算对两个数求和

使用位运算对两个数求和

#使用位运算对两个数求和| 来源: 网络整理| 查看: 265

标签:coding   elf   utf-8   bsp   取反   while   subject   color   异或   

题目描述 写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。 思路: 异或:求各位只和 与:计算进位 Python代码 1 # -*- coding:utf-8 -*- 2 class Solution: 3 def Add(self, num1, num2): 4 # write code here 5 pos_sum = num1 6 while num2: 7 pos_sum = (num1^num2)& 0xffffffff 8 num2 = ((num1&num2)


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有